﻿''' <summary>Dataset for manupulating and obtaining dictionary data</summary>
Partial Class ĐŘječnikData
#Region "DataTables"
    ''' <summary>Represents combinations of two languages</summary>
    Partial Class CombinationDataTable
    End Class
    ''' <summary>Represents translations of word from one language to another</summary>
    Partial Class TranslationDataTable
    End Class
    ''' <summary>Represents words</summary>
    Partial Class WordDataTable
    End Class
    ''' <summary>Represents relations between two words in same language</summary>
    Partial Class RelationDataTable
    End Class
    ''' <summary>Represents dictionaries</summary>
    Partial Class DictionaryDataTable
    End Class
#End Region
#Region "Rows"
    ''' <summary>Represents single language combination</summary>
    Partial Class CombinationRow
        ''' <summary>Returns a <see cref="System.String"/> that represents the current <see cref="CombinationRow"/>.</summary>
        ''' <returns>A <see cref="System.String"/> that represents the current <see cref="CombinationRow"/></returns>
        Public Overrides Function ToString() As String
            Return Me.Lang1Code & " - " & Me.Lang2Code
        End Function
    End Class
    ''' <summary>Represents single dictionary</summary>
    Partial Class DictionaryRow
    End Class
    ''' <summary>represents single relation between two words in same language</summary>
    Partial Class RelationRow
        ''' <summary>Kind of relation</summary>
        Public Property RelationType() As ImportExport.enmRelation
            Get
                Return Me.Type
            End Get
            Set(ByVal value As ImportExport.enmRelation)
                Me.Type = value
            End Set
        End Property
    End Class
    ''' <summary>Represents single translation from one language to anotehr</summary>
    Partial Class TranslationRow
    End Class
    ''' <summary>Represents single word</summary>
    Partial Class WordRow
        ''' <summary>Gets dictionary to which this word belongs</summary>
        Public Function GetDictionary() As DictionaryRow
            Static Dictionary As DictionaryRow
            If Dictionary Is Nothing Then
                Dim taDic As New ĐŘječnikDataTableAdapters.taDictionary
                Dim Table As DictionaryDataTable = taDic.GetByID(Me.Dic)
                If Table.Rows.Count > 0 Then
                    Dictionary = Table.Rows(0)
                    Return Table.Rows(0)
                Else
                    Return Nothing
                End If
            Else
                Return Dictionary
            End If
        End Function
        ''' <summary>Code of language of this word</summary>
        Public ReadOnly Property LngCode() As String
            Get
                If Me.Lang = 1 Then
                    Return GetDictionary.Lang1Code
                Else
                    Return GetDictionary.Lang2Code
                End If
            End Get
        End Property
        ''' <summary>Gets translations of current word</summary>
        Public Function GetTranslations() As WordDataTable
            Dim Table As New ĐŘječnikDataTableAdapters.taWord
            Return Table.GetWordTranslations(Me.ID, If(Me.Lang = 1, 2, 1))
        End Function
        ''' <summary>Gets relations of this word</summary>
        ''' <param name="Type">Type of relation</param>
        ''' <param name="Back">True for backward relation</param>
        ''' <returns>Words related to his word in specified manner</returns>
        Public Function GetRelations(ByVal Type As ImportExport.enmRelation, Optional ByVal Back As Boolean = False) As WordDataTable
            Dim Table As New ĐŘječnikDataTableAdapters.taWord
            Return Table.GetRelations(Me.ID, Type, Back)
        End Function
        ''' <summary>Type of word</summary>
        Public Property WordType() As ImportExport.enmType
            Get
                If Me.IsTypeNull Then Return ImportExport.enmType.NA Else Return Me.Type
            End Get
            Set(ByVal value As ImportExport.enmType)
                Me.Type = value
            End Set
        End Property
    End Class
#End Region
End Class
#Region "Table adapters"
Namespace ĐŘječnikDataTableAdapters
    ''' <summary>Manipulates dictionaries in database</summary>
    Partial Class taDictionary
    End Class
    ''' <summary>manipulates one-way relation between two words from same language in database</summary>
    Partial Class taRelation
    End Class
    ''' <summary>Manipulates two-way translation between two words from different languages in database</summary>
    Partial Class taTranslation
    End Class
    ''' <summary>Manipulate words in database</summary>
    Partial Class taWord
        ''' <summary>Fills given <see cref="ĐŘječnikData.WordDataTable"/> by words according to given search pattern (against native script)</summary>
        ''' <param name="dataTable">Data table to fill</param>
        ''' <param name="FromLng">Source language code</param>
        ''' <param name="ToLng">Code of the other language from dictionary</param>
        ''' <param name="Search">SQL search pattern (use _ and %)</param>
        ''' <returns>The number of rows successfully added to or refreshed in the <see cref="System.Data.DataSet"/>. This does not include rows affected by statements that do not return rows.</returns>
        <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Fill, False)> _
        Public Overloads Function FillBySearch(ByVal dataTable As ĐŘječnikData.WordDataTable, ByVal FromLng As String, ByVal ToLng As String, ByVal Search As String, ByVal Mode As SearchMode) As Integer
            Dim dbSearch As String
            Select Case Mode
                Case SearchMode.Begins : dbSearch = Search & "%"c
                Case SearchMode.Contains : dbSearch = "%"c & Search & "%"c
                Case Else : dbSearch = Search
            End Select
            Dim Compare$ = Search & "%"c
            Return Me.FillBySearch(dataTable, FromLng.ToLower, ToLng.ToLower, dbSearch, FromLng.ToLower, ToLng.ToLower, dbSearch, Search, Search, Compare, Compare)
        End Function
        ''' <summary>Searches for words in dictionaries of given laguages for word fullfilling given search pattern (against native script)</summary>
        ''' <param name="FromLng">Source language code</param>
        ''' <param name="ToLng">Code of the other language from dictionary</param>
        ''' <param name="Search">SQL search pattern (use _ and %)</param>
        ''' <returns>The <see cref="ĐŘječnikData.WordDataTable"/> containing words found</returns>
        <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.[Select], False)> _
        Public Overloads Function GetBySearch(ByVal FromLng As String, ByVal ToLng As String, ByVal Search As String, ByVal Mode As SearchMode) As ĐŘječnikData.WordDataTable
            Dim dbSearch As String
            Select Case Mode
                Case SearchMode.Begins : dbSearch = Search & "%"c
                Case SearchMode.Contains : dbSearch = "%"c & Search & "%"c
                Case Else : dbSearch = Search
            End Select
            Dim Compare$ = Search & "%"c
            Return GetBySearch(FromLng.ToLower, ToLng.ToLower, dbSearch, FromLng.ToLower, ToLng.ToLower, dbSearch, Search, Search, Compare, Compare)
        End Function
        ''' <summary>Fills given <see cref="ĐŘječnikData.WordDataTable"/> by words according to given search pattern (against latin transliteration)</summary>
        ''' <param name="dataTable">Data table to fill</param>
        ''' <param name="FromLng">Source language code</param>
        ''' <param name="ToLng">Code of the other language from dictionary</param>
        ''' <param name="Search">SQL search pattern (use _ and %)</param>
        ''' <returns>The number of rows successfully added to or refreshed in the <see cref="System.Data.DataSet"/>. This does not include rows affected by statements that do not return rows.</returns>
        <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Fill, False)> _
        Public Overloads Function FillBySearchLatin(ByVal dataTable As ĐŘječnikData.WordDataTable, ByVal FromLng As String, ByVal ToLng As String, ByVal Search As String, ByVal Mode As SearchMode) As Integer
            Dim dbSearch As String
            Select Case Mode
                Case SearchMode.Begins : dbSearch = Search & "%"c
                Case SearchMode.Contains : dbSearch = "%"c & Search & "%"c
                Case Else : dbSearch = Search
            End Select
            Dim Compare$ = Search & "%"c
            Return Me.FillBySearchLatin(dataTable, FromLng.ToLower, ToLng.ToLower, dbSearch, FromLng.ToLower, ToLng.ToLower, dbSearch, Search, Search, Compare, Compare)
        End Function
        ''' <summary>Searches for words in dictionaries of given laguages for word fullfilling given search pattern (against latin transliteration)</summary>
        ''' <param name="FromLng">Source language code</param>
        ''' <param name="ToLng">Code of the other language from dictionary</param>
        ''' <param name="Search">SQL search pattern (use _ and %)</param>
        ''' <returns>The <see cref="ĐŘječnikData.WordDataTable"/> containing words found</returns>
        <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.[Select], False)> _
        Public Overloads Function GetBySearchLatin(ByVal FromLng As String, ByVal ToLng As String, ByVal Search As String, ByVal Mode As SearchMode) As ĐŘječnikData.WordDataTable
            Dim dbSearch As String
            Select Case Mode
                Case SearchMode.Begins : dbSearch = Search & "%"c
                Case SearchMode.Contains : dbSearch = "%"c & Search & "%"c
                Case Else : dbSearch = Search
            End Select
            Dim Compare$ = Search & "%"c
            Return GetBySearchLatin(FromLng.ToLower, ToLng.ToLower, dbSearch, FromLng.ToLower, ToLng.ToLower, dbSearch, Search, Search, Compare, Compare)
        End Function

        ''' <summary>Fills data table translations of word with specified ID</summary>
        ''' <param name="DataTable">Data table to fill</param>
        ''' <param name="Src">ID of word of which to search for translations</param>
        ''' <param name="TargLang">Language of returned words (1 or 2) should be other than lang of <paramref name="Src"/></param>
        ''' <returns>The number of rows successfully added to or refreshed in the <see cref="System.Data.DataSet"/>. This does not include rows affected by statements that do not return rows.</returns>
        <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Fill, False)> _
        Public Overloads Function FillByWordTranslations(ByVal DataTable As ĐŘječnikData.WordDataTable, ByVal Src As Integer, ByVal TargLang As Byte) As Integer
            Return Me.FillByWordTranslations(DataTable, Src, TargLang, Src, TargLang)
        End Function
        ''' <summary>Gets words that are translations of word with specified ID</summary>
        ''' <param name="Src">ID of word of which to search for translations</param>
        ''' <returns>Translations of word with ID <paramref name="Src"/></returns>
        ''' <param name="TargLang">Language of returned words (1 or 2) should be other than lang of <paramref name="Src"/></param>
        <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.[Select], False)> _
        Public Overloads Function GetWordTranslations(ByVal Src As Integer, ByVal TargLang As Byte) As ĐŘječnikData.WordDataTable
            Return Me.GetWordTranslations(Src, TargLang, Src, TargLang)
        End Function
        ''' <summary>Fills data table with words related to word with specified ID</summary>
        ''' <param name="DataTable">Data table to fill</param>
        ''' <param name="Src">ID of source word</param>
        ''' <param name="Type">Type of relation</param>
        ''' <param name="Back">True for back references</param>
        ''' <returns>The number of rows successfully added to or refreshed in the <see cref="System.Data.DataSet"/>. This does not include rows affected by statements that do not return rows.</returns>
        <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Fill, False)> _
        Public Overloads Function FillByRelations(ByVal DataTable As ĐŘječnikData.WordDataTable, ByVal Src As Int32, ByVal Type As ImportExport.enmRelation, Optional ByVal Back As Boolean = False) As Integer
            Return Me.FillByRelations(DataTable, Type, Src, Src, Back, Back)
        End Function
        ''' <summary>Gets words related to word with specified ID</summary>
        ''' <param name="Src">ID of source word</param>
        ''' <param name="Type">Type of relation</param>
        ''' <param name="Back">True for back references</param>
        <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.[Select], False)> _
        Public Overloads Function GetRelations(ByVal Src As Int32, ByVal Type As ImportExport.enmRelation, Optional ByVal Back As Boolean = False) As ĐŘječnikData.WordDataTable
            Return Me.GetRelations(Type, Src, Src, Back, Back)
        End Function
    End Class
    ''' <summary>Gats combination fo languages provided by dictionaries in database</summary>
    Partial Class taCombination
    End Class
End Namespace
#End Region






